#ifndef FFMPEG_IMPL_H
#define FFMPEG_IMPL_H
extern "C"
{
    #include "libavformat/avformat.h"
    #include "libavcodec/avcodec.h"
    #include "libavutil/mem.h"
    #include "libswscale/swscale.h"
}
#include "stdint.h"
class FFMPEG_Impl
{
public:
    FFMPEG_Impl();
    ~FFMPEG_Impl();
public:
    void Init(int width ,  int height );
    bool decode_video(int &frameFinished, uint8_t *data, int size,unsigned char *rgb24,int &nLen);
    void YUV420p_to_RGB24_2(unsigned char *yuv420[3], unsigned char *rgb24, int width, int height);
    void colse();
private:
//    void (*p_avcodec_init)(void);

//    void (*p_av_register_all)(void);

//    AVCodecContext *(*p_avcodec_alloc_context)(void);

//    AVCodec* (*p_avcodec_find_decoder)(enum AVCodecID id);

//    int (*p_avcodec_open)(AVCodecContext *avctx, AVCodec *codec);

//    AVFrame *(*p_avcodec_alloc_frame)(void);

//    void (*p_av_init_packet)(AVPacket *pkt);

//    int (*p_avcodec_decode_video2)(AVCodecContext *avctx, AVFrame *picture,
//                             int *got_picture_ptr,
//                             AVPacket *avpkt);

//    int (*p_avcodec_close)(AVCodecContext *avctx);

//    void (*p_av_free)(void *ptr);

//    struct SwsContext *(*p_sws_getContext)(int srcW, int srcH, enum PixelFormat srcFormat,
//                                      int dstW, int dstH, enum PixelFormat dstFormat,
//                                      int flags, SwsFilter *srcFilter,
//                                      SwsFilter *dstFilter, const double *param);

//    int (*p_sws_scale)(struct SwsContext *context, const uint8_t* const srcSlice[], const int srcStride[],
//                  int srcSliceY, int srcSliceH, uint8_t* const dst[], const int dstStride[]);
//    void (*p_sws_freeContext)(struct SwsContext *swsContext);

private:
    AVFrame *pFrame_;

    AVCodecContext *codec_;

    /* find the video encoder */
    AVCodec *videoCodec;

    void * libm_handle_codec;
    //void * libm_handle_format;
    void * libm_handle_util;
    void * libm_handle_scale;

    SwsContext* img_convert_ctx;

    AVFrame * pFrameRGB24;
    AVFrame * pFrameYUV;

    uint8_t *bufferYUV ;
    uint8_t *bufferRGB ;
};

#endif // FFMPEG_IMPL_H
